Fix TZC-400 peripheral detection
authorVikram Kanigiri <[email protected]>
Tue, 20 Oct 2015 15:55:26 +0000 (16:55 +0100)
committerVikram Kanigiri <[email protected]>
Fri, 27 Nov 2015 13:47:13 +0000 (13:47 +0000)
The TZC-400 driver implementation incorrectly uses the component
ID registers to detect the TZC-400 peripheral. As all ARM
peripherals share the same component ID, it doesn't allow to
uniquely identify the TZC-400 peripheral. This patch fixes the
TZC-400 driver by relying on the `part_number_0` and
`part_number_1` fields in the `PID` registers instead.
The `tzc_read_component_id` function has been replaced by
`tzc_read_peripheral_id`, which reads the 'part_number' values
and compares them with the TZC-400 peripheral ID.

Also, it adds a debug assertion to detect when the TZC driver
initialisation function is called multiple times.

Change-Id: I35949f6501a51c0a794144cd1c3a6db62440dce6

drivers/arm/tzc400/tzc400.c
include/drivers/arm/tzc400.h

index 4b72a2bb19384f0c3fef0bbdd58aada8f2ad16b4..940e00e0cd67721511723f388491f383d09a3d0a 100644 (file)
@@ -118,14 +118,13 @@ static inline void tzc_write_region_id_access(uintptr_t base,
                REGION_NUM_OFF(region), val);
 }
 
-static uint32_t tzc_read_component_id(uintptr_t base)
+static unsigned int tzc_read_peripheral_id(uintptr_t base)
 {
-       uint32_t id;
+       unsigned int id;
 
-       id = mmio_read_8(base + CID0_OFF);
-       id |= (mmio_read_8(base + CID1_OFF) << 8);
-       id |= (mmio_read_8(base + CID2_OFF) << 16);
-       id |= (mmio_read_8(base + CID3_OFF) << 24);
+       id = mmio_read_8(base + PID0_OFF);
+       /* Masks jep106_id_3_0 part in PID1 */
+       id |= ((mmio_read_8(base + PID1_OFF) & 0xF) << 8);
 
        return id;
 }
@@ -166,17 +165,21 @@ static void tzc_set_gate_keeper(uintptr_t base, uint8_t filter, uint32_t val)
 
 void tzc_init(uintptr_t base)
 {
-       uint32_t tzc_id, tzc_build;
+       unsigned int tzc_id;
+       unsigned int tzc_build;
 
        assert(base);
+
+       /* Assert if already initialised */
+       assert(!tzc.base);
+
        tzc.base = base;
 
        /*
-        * We expect to see a tzc400. Check component ID. The TZC-400 TRM shows
-        * component ID is expected to be "0xB105F00D".
+        * We expect to see a tzc400. Check peripheral ID.
         */
-       tzc_id = tzc_read_component_id(tzc.base);
-       if (tzc_id != TZC400_COMPONENT_ID) {
+       tzc_id = tzc_read_peripheral_id(tzc.base);
+       if (tzc_id != TZC400_PERIPHERAL_ID) {
                ERROR("TZC : Wrong device ID (0x%x).\n", tzc_id);
                panic();
        }
index a5312c47ee44e8eaa54e22d3273ee312ee215943..f8e1664efdc2af6a1d5fabb2a33b4279311d88c0 100644 (file)
 #define TZC_REGION_ACCESS_RDWR(id)                                     \
                (TZC_REGION_ACCESS_RD(id) | TZC_REGION_ACCESS_WR(id))
 
-#define TZC400_COMPONENT_ID    0xb105f00d
+/* Consist of part_number_1 and part_number_0 */
+#define TZC400_PERIPHERAL_ID   0x0460
+
 
 
 #ifndef __ASSEMBLY__